﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RedDragon.Common.Dtos;
using RedDragon.ERP.API.Application.Commands.Proccess;
using T.Common.Domain.Common;

namespace RedDragon.ERP.API.Controllers
{
    /// <summary>
    /// 工艺控制器
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class ProcessController : ControllerBase
    {
        private readonly IMediator _mediator;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public ProcessController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 获取物料 绑定下拉
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet("SearchLogistics")]
        public async Task<Result> SearchLogistics([FromQuery] SearchLogisticsCommand cmd)
        {
            return await _mediator.Send(cmd);
        }

        /// <summary>
        /// 根据物料ID获取物料规格
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet("SearchCondition")]
        public async Task<Result> SearchCondition([FromQuery] SearchConditionCommand cmd)
        {
            return await _mediator.Send(cmd);
        }

        /// <summary>
        /// 添加工艺路线
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("CreateProcessRoute")]
        public async Task<Result> CreateProcessRoute(CreateProcessRouteCommand cmd)
        {
            cmd.CreatedTime = DateTime.Now;
            return await _mediator.Send(cmd);
        }

        /// <summary>
        /// 获取工艺路线列表
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("SearchProcessRoute")]
        public async Task<Result<PageResultDto<ProcessRouteDtos>>> SearchProcessRoute(SearchProcessRouteCommand cmd)
        {
            return await _mediator.Send(cmd);
        }

        /// <summary>
        /// 添加工艺路线工序
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("CreateOperation")]
        public async Task<Result> CreateOperation(CreateOperationCommand cmd)
        {
            cmd.CreatedTime = DateTime.Now;
            return await _mediator.Send(cmd);
        }

        /// <summary>
        /// 无条件获取工序
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("SearchProcess")]
        public async Task<Result> SearchProcess(SearchProcessCommand cmd)
        {
            return await _mediator.Send(cmd);
        }

        /// <summary>
        /// 根据工序Id获取工作中心
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("SerchWorkCenters")]
        public async Task<Result> SerchWorkCenters(SearchWorkCentersCommon cmd)
        {
            return await _mediator.Send(cmd);
        }

        /// <summary>
        /// 显示工艺路线工序
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("SearchOperation")]
        public async Task<Result<PageResultDto<OperationsDto>>> SearchOperation(SearchOperationCommand cmd)
        {
            return await _mediator.Send(cmd);
        }

        /// <summary>
        /// 获取工艺路线详情
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("DetailsProcessRoute")]
        public async Task<Result> DetailsProcessRoute(DetailsProcessRouteCommand cmd)
        {
            return await _mediator.Send(cmd);
        }
    }
}
